package com.ftg.learn.bus.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ftg.learn.bus.entity.Director;
import com.ftg.learn.bus.service.IDirectorService;
import com.ftg.learn.util.ResEntity;
import com.ftg.learn.util.ResPageEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 * 负责人表 前端控制器
 * </p>
 *
 * @author lalala
 * @since 2022-03-07
 */
@RestController
@RequestMapping("/bus/director")
@Api(tags = "负责人管理功能列表")
public class DirectorController extends CrudpController<Director, IDirectorService> {

    /**
     * 查询车的信息和负责人的信息
     * @return data
     */
    @GetMapping("/showDirectorBusInfo")
    @ApiOperation(value = "查询车的信息和负责人的信息(真)")
    public ResEntity showDirectorBusInfo(){
        return new ResEntity(0,"success",super.service.showDirectorBusInfo());
    }



    @GetMapping("/showDirectorBusInfoByDid")
    @ApiOperation(value = "根据负责人查询其负责的车的信息(真)")
    public ResEntity showDirectorBusInfoByDid(@RequestParam Long did){
        return new ResEntity(0,"success",super.service.showDirectorBusInfoByDid(did));
    }

    @PutMapping("/updateBusInfoDirectorByBid")
    @ApiOperation(value = "逻辑删除负责人并且修改公车信息的负责人(真,3参数)")
    public ResEntity updateBusInfoDirectorByBid(@RequestParam Long did,@RequestParam Long bid,@RequestParam Long newDid){
        return super.service.updateBusInfoDirectorByBid(did,bid,newDid) ? resEntity.OK() : resEntity.Failure("操作失败，请重试!");
    }


    @DeleteMapping("/updateBusInfoDidDeleteDirectorByBid")
    @ApiOperation("逻辑删除负责人并且修改公车信息的负责人(真,2参数)")
    public ResEntity updateBusInfoDidDeleteDirectorByBid(Long newDid,Long bid){
        return super.service.updateBusInfoDidDeleteDirectorByBid(newDid,bid) ? resEntity.OK() : resEntity.Failure("操作失败，请重试!");
    }



    @PutMapping("/updateDid")
    @ApiOperation(value = "修改负责人")
    public ResEntity updateInfoDid(@RequestParam Long did,@RequestParam Long  newDid){
        return super.service.updateInfoDid(did,newDid)?resEntity.OK():resEntity.Failure("修改失败.............");
    }

    @GetMapping("/showHistoryDirector")
    @ApiOperation(value = "展示历史负责人信息")
    public ResEntity showHistoryDirector(@RequestParam int page,@RequestParam int limit){
        Page<Director> p = new Page<>(page,limit);
        p.setRecords(super.service.showHistoryDirector(p));
        return new ResPageEntity(p);

    }
}
